-
Notifications
You must be signed in to change notification settings - Fork 62
[generator] Fix UnsupportedOSPlatform for property setters when base has getter-only
#1374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…e has getter-only Context: dotnet/android#10510 (comment) When a derived class has a property setter with `ApiRemovedSince`, but the base class only has a getter (no setter), clear the setter's `ApiRemovedSince` if the base getter is not removed. Also handle standalone `setXxx` methods that correspond to base class properties. Fixes `CA1416` warning for `ListView.Adapter.set` being incorrectly marked as unsupported on `android15.0`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes incorrect UnsupportedOSPlatform attribute generation for property setters when the base class only has a getter. The fix addresses CA1416 warnings by clearing ApiRemovedSince on derived class setters when the base property (accessed via its getter) is not marked as removed.
Key Changes:
- Adds logic to handle property setters in derived classes when base class has getter-only properties
- Adds handling for standalone
setXxxmethods that correspond to base class properties - Includes test coverage for the property setter scenario
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenBase.cs | Adds three conditional blocks to clear ApiRemovedSince on setters: one for class properties (lines 369-373), one for standalone setter methods (lines 380-393), and one for interface properties (lines 441-444) |
| tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs | Adds test UnsupportedOSPlatformIgnoresPropertySetterOverridesWhenBaseHasGetterOnly to verify the fix for ListView.Adapter scenario |
Updated property override logic to match base properties by name only, allowing for covariant return and contravariant parameter types. This prevents incorrectly marking overridden getters/setters as removed when the base property is not removed, even if the return or parameter types differ. Added a unit test to verify that [UnsupportedOSPlatform] is not applied in these covariant override scenarios.
…# names When a derived class property has a different C# name than the base class property but the same Java getter/setter names (e.g., ListView.Adapter vs AdapterView.RawAdapter both using getAdapter/setAdapter), the ApiRemovedSince fixup now correctly matches by Java method name instead of only by C# property name. This prevents incorrect [UnsupportedOSPlatformAttribute] generation on property accessors when the base class accessor is still available.
Context: dotnet/android#10510 (comment)
When a derived class has a property setter with
ApiRemovedSince, but the base class only has a getter (no setter), clear the setter'sApiRemovedSinceif the base getter is not removed. Also handle standalonesetXxxmethods that correspond to base class properties.Fixes
CA1416warning forListView.Adapter.setbeing incorrectly marked as unsupported onandroid15.0.